/**
 * 
 */
package arisufascion.com.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.TabHost;
import arisufascion.com.MainApplication;
import arisufascion.com.R;
import arisufascion.com.constant.Constants;
import arisufascion.com.constant.WriteLog;
import arisufascion.com.db.ProductDataSource;
import arisufascion.com.tabs.BadgeTabManager;
import arisufascion.com.tabs.BadgeTabWidget;
import arisufascion.com.tabs.TabGroupOneActivity;
import arisufascion.com.tabs.TabGroupThreeActivity;
import arisufascion.com.tabs.TabGroupTwoActivity;

/**
 * @author Kelvin
 * 
 */
public class TabsActivity extends TabActivity {
	TabHost tabHost;
	Resources res;
	public static TabsActivity tabParent;
	private ProductDataSource database;

	/** Called when the activity is first created. */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_main);
		database = new ProductDataSource(this);
		database.open();
		tabParent = this;

		res = getResources(); // Resource object to get Drawables
		TabHost tabHost = getTabHost(); // The activity TabHost
		TabHost.TabSpec spec; // Resusable TabSpec for each tab
		Intent intent; // Reusable Intent for each tab

		// --------------------------
		View tabIndicator_home = LayoutInflater.from(this).inflate(
				R.layout.tab_indicator_home, getTabWidget(), false);

		intent = new Intent().setClass(this, TabGroupOneActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		spec = tabHost.newTabSpec("tab1").setIndicator(tabIndicator_home)
				.setContent(intent);
		tabHost.addTab(spec);

		View tabIndicator_cart = LayoutInflater.from(this).inflate(
				R.layout.tab_indicator_shopping, getTabWidget(), false);

		intent = new Intent().setClass(this, TabGroupTwoActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		spec = tabHost.newTabSpec("tab2").setIndicator(tabIndicator_cart)
				.setContent(intent);
		tabHost.addTab(spec);

		View tabIndicator_feedback = LayoutInflater.from(this).inflate(
				R.layout.tab_indicator_feeback, getTabWidget(), false);

		intent = new Intent().setClass(this, TabGroupThreeActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		spec = tabHost.newTabSpec("tab3").setIndicator(tabIndicator_feedback)
				.setContent(intent);
		tabHost.addTab(spec);

		tabHost.setCurrentTab(0);

		int index = database.getProducts().size();

		WriteLog.d("Kelvin", index + "");

		BadgeTabWidget tabWidget = (BadgeTabWidget) this
				.findViewById(android.R.id.tabs);
		BadgeTabManager.init(tabWidget);
		BadgeTabManager.getInstance().setBadgeAtIndex(index, 1);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		return super.onKeyDown(keyCode, event);
	}
}
